import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';

export interface LoginData {
	client_id : string|"topcOjWeb",
	client_secret : string|"topcOjWeb",
	grant_type : string|"password",
	username : {
		number : string, 
		password : string, 
		authType : string|"password", 
		oauthEndpoint : string|"admin"
	};
}

export function generateLoginData(_number: string, _password: string): LoginData {
  const loginData: LoginData = {
    client_id: "topcOjWeb",
    client_secret: "topcOjWeb",
    grant_type: "password",
    username: {
      number: _number,
      password: _password,
      authType: "password",
      oauthEndpoint: "admin",
    },
  };
  return loginData;
}

export interface LoginRes {
	token : string;
}

export function login(params: { type: LoginData }) {
	return axios.get<LoginRes>('/auth/oauth/token', {params});
}

export function logout() {
	return axios.get<LoginRes>('/participant/open/admin/logout');
}

export function getUserInfo() {
	return axios.get<UserState>('/participant/close/admin/info');
}

export function getMenuList() {
	return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}